export function useEventListener(...args: any[]) {
  const element = typeof args[0] === 'string' ? window : args.shift()

  let off = () => {}

  const stop = watch(
    () => unref(element),
    el => {
      if (!el) return

      off()
      unref(element).addEventListener(...args)
      off = () => unref(element).removeEventListener(...args)
    },
    {
      immediate: true
    }
  )

  onScopeDispose(() => off())

  return () => {
    off()
    stop()
  }
}
